package com.tpp.order.controller;

import com.tpp.comm.pojo.TpOrder;
import com.tpp.comm.util.OrderLineUpException;
import com.tpp.comm.vo.Result;
import com.tpp.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@Slf4j
public class OrderController {

    @Resource
    private OrderService orderService;

    @GetMapping("/v/confirmpay")
    public Result confirmpay(String orderNo){
        try {
            TpOrder tpOrder = orderService.searchOrder(orderNo);
            return Result.success(tpOrder);
        } catch (OrderLineUpException e){
            return Result.builder().errorCode("401").msg(e.getMessage()).build();
        } catch (RuntimeException e){
            return Result.builder().errorCode("404").msg(e.getMessage()).build();
        } catch (Exception e){
            e.printStackTrace();
            log.error(e.getMessage());
            return Result.fail("系统繁忙");
        }
    }

}
